package com.s.core.root.strategy.factor;

import com.s.core.root.D;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class MaxVol {
    /**
     * 是否是days日内的最大成交量
     */
    public static boolean isMaxVol(D d, int[] offset, int days) {
        return Arrays.stream(offset).anyMatch(o -> isMaxVol(d, o, days));
    }

    private static boolean isMaxVol(D d, int offset, int days) {
        if (d.isTp()) {
            return false;
        }
        D bd = d.bDaily(offset);
        if (bd.isTp()) {
            return false;
        }
        List<D> dList = bd.bDailyList(days);
        D maxD = dList.stream().filter(t -> !t.isTp()).
                max(Comparator.comparing(t -> new BigDecimal(t.vol))).orElse(null);
        return maxD != null && maxD == bd;
    }
}
